#nullable enable
using System.ComponentModel.DataAnnotations;
using SqlSugar;

namespace FytSoa.Domain.Sys;

/// <summary>
/// 用户登录会话信息。
/// </summary>
[SugarTable("sys_user_session")]
public class SysUserSession
{
    [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
    public long Id { get; set; }

    [Required]
    [SugarColumn(ColumnName = "tenant_id")]
    public long TenantId { get; set; }

    [Required]
    [SugarColumn(ColumnName = "user_id")]
    public long UserId { get; set; }

    [Required]
    [StringLength(255)]
    [SugarColumn(ColumnName = "refresh_token_hash")]
    public string RefreshTokenHash { get; set; } = string.Empty;

    [SugarColumn(ColumnName = "issued_at")]
    public DateTime IssuedAt { get; set; }

    [SugarColumn(ColumnName = "expires_at")]
    public DateTime ExpiresAt { get; set; }

    [SugarColumn(ColumnName = "revoked_at")]
    public DateTime? RevokedAt { get; set; }

    [StringLength(500)]
    [SugarColumn(ColumnName = "user_agent")]
    public string? UserAgent { get; set; }

    [StringLength(64)]
    [SugarColumn(ColumnName = "ip_address")]
    public string? IpAddress { get; set; }

    /// <summary>
    /// 额外元数据(JSON)。
    /// </summary>
    [SugarColumn(ColumnName = "metadata", IsJson = true)]
    public string? Metadata { get; set; }
}
